﻿IF OBJECT_ID('up_Utility_Asset_Distribution_ValidateIds') IS not NULL
	DROP PROC up_Utility_Asset_Distribution_ValidateIds 

GO 


CREATE PROCEDURE [dbo].[up_Utility_Asset_Distribution_ValidateIds]
(
	@utilityId int,
	@assetIdList varchar(max)
)
AS

SELECT 
	CAST(Value AS int) as AssetId
FROM
	(select 
		Value 
	 from 
		dbo.fn_Split(@assetIdList, default)
	) as List
WHERE
	Value NOT IN (
		SELECT 
			Utility_Asset_DistributionId 
		FROM
			tb_Utility_Asset_Distributions assets
		WHERE 
			assets.UtilityFk = @utilityId
	)
 